<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    :destroy-on-close="close_modal_destroy"
    :close-on-click-modal="close_modal"
    @close="handleCancel"
    width="300px"
    append-to-body
  >
    <el-input
      type="textarea"
      :rows="2"
      placeholder="在此输入评论内容..."
      v-model="context">
    </el-input>
    <div style="text-align: right;width: 100%">
      <el-button @click="sendComment">发布</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addSonComment} from "@/api/liveShare";
export default {
  name: "addComment",
  data() {
    return {
      title: '回复评论',
      visible: false,
      close_modal_destroy: true,
      close_modal: false,
      context: undefined,
      parnetId: undefined,
      reponseId: null
    }
  },
  methods: {
    /**
     *
     * @param id 被评论者id
     * @param isParent 是否为
     */
    add(parnetId,reponseId) {
      this.visible = true
      this.parnetId = parnetId
      this.reponseId = reponseId
    },
    async sendComment() {
      var comment = {
        parentId: this.parnetId,
        context: this.context,
        responseId: this.reponseId
      }
      await addSonComment(comment).then(res => {
        if (res.body.data)
          this.$message.success("评论成功")
        else
          this.$message.error("请重新评论")
      })
      this.$emit('ok')
      this.close()
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.parnetId = undefined
      this.reponseId = null
      this.context = undefined
      this.$emit('close')
      this.visible = false
    }
  },

}
</script>

<style scoped>

</style>
